<?php
class Evebit_Email_Helper extends Zend_Mail {
	protected $username = null;
	
	protected $password = null;
	
	public function __construct($options = array(), $charset = 'UTF-8') {
		parent::__construct ( $charset );
		
		$configEntity = new Default_Model_Entity_Config ();
		$username = $configEntity->getCodeValue ( 'send_admin' );
		$password = $configEntity->getCodeValue ( 'send_password' );
		
		$this->username = array_key_exists ( 'username', $options ) ? $options ['username'] : $username;
		$this->password = array_key_exists ( 'password', $options ) ? $options ['password'] : $password;
	}
	
	public function getFullBasePath() {
		$http = new Zend_Controller_Request_Http ();
		return $http->getScheme () . '://' . $http->getHttpHost () . $http->getBaseUrl ();
	}
	
	public function sendConfirmSuccessEmail($user){
		$base_url = $this->getFullBasePath ();
	    $image_baseUrl = $this->getFullBasePath () . '/media/images' ;
	    $username = $user->username;
	    $configEntity = new Default_Model_Entity_Config ();
		$mail_to = $configEntity->getCodeValue ( 'send_admin' );
	    
		$Entrepenuer_content = <<<EOF
		<body>
<style type="text/css">
<!--
body {
   background-color: #262626;
   margin: 0;
   padding: 0;
}
a {
	color:#2d78d2;
	text-decoration:none;
}
a:hover {
	color:#2d78d2;
	text-decoration:underline;
}
img {
	border: none;
	}
-->
</style>
<!-- START OF PAGE WRAPPER -->
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#262626">
  <tr>
    <td valign="top">
    
    
    
    	<!-- START OF ACCESSIBILITY MESSAGE -->
    	<table width="650" border="0" align="center" cellpadding="10" cellspacing="0" bgcolor="#262626">
  			<tr>
    				<td width="58%" style="font-family: Arial, Helvetica, sans-serif; font-size: 11px; color: #768390;"><p>Don't miss out, add <a href="#" style="color:#2d78d2; font-family: Helvetica, Arial, sans-serif;">info@businessandbling.co.uk</a> to your address book</p></td>
    				<td width="19%" style="font-family: Arial, Helvetica, sans-serif; font-size: 11px; color: #768390;"><p><a href="#" style="color:#2d78d2; font-family: Helvetica, Arial, sans-serif;">Forward to a friend</a></p></td>
    				<td width="23%" style="font-family: Arial, Helvetica, sans-serif; font-size: 11px; color: #768390;"><p>View Online <a href="$base_url" style="color:#2d78d2; font-family: Helvetica, Arial, sans-serif;">Click Here</a></p></td>
  			</tr>
		</table>
		<!-- END OF ACCESSIBILITY MESSAGE -->
      
      
      <!-- START OF EMAIL WRAPPER -->
      <table width="650" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#fcfcfc">
        <tr>
          <td>            
            <!-- START OF Header Table -->
            <table width="650" height="93" border="0" cellspacing="0" cellpadding="0" bgcolor="#fcfcfc">
              <tr>
                <td height="93" width="415"  align="left" valign="top" bgcolor="#ededed"><img src="$image_baseUrl/logo.jpg" width="397" height="93" alt="your logo text here" /></td>
                <td width="189" align="right" valign="middle" bgcolor="#ededed"><a href="http://www.facebook.com/pages/Business-and-Bling/139080916179736"><img src="$image_baseUrl/facebook.jpg" alt="Facebook" width="30" height="22" border="0" /></a>
                <a href="https://twitter.com/#!/businessbling"><img src="$image_baseUrl/twitter.jpg" alt="Twitter" width="30" height="22" border="0" /></a></td>
                <td width="10" height="93" align="right" valign="top" bgcolor="#ededed">&nbsp;</td>
              </tr>
            </table>
            <!-- END OF Header Table -->          
            <!-- START OF splash Table -->  
            <table width="650" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td height="217" valign="top"><a href="http://businessandbling.co.uk/free-business-plan-software-tour/"><img src="$image_baseUrl/header_splash5.jpg" alt="header splash" width="650" height="627" border="0" /></a></td>
              </tr>
            </table>
            <!-- END OF splash Table -->
          
             <!-- START OF 3 Column Product Display Table --><!-- END OF 3 Column Product Display Table -->  
          
            <!-- START OF QUOTE TABLE -->
      <table width="630" border="0" align="center" cellpadding="0" cellspacing="0">
  				<tr>
    				<td colspan="3" height="37"><img src="$image_baseUrl/hr.jpg" width="630" height="37" alt="hr1" /></td>
  				</tr>
  				<tr>
  				  <td height="81" colspan="3" align="center" valign="top" bgcolor="#fcfcfc" style="font-family: Helvetica, Arial, sans-serif; color: #2d78d2; font-size: 24px;"><img src="$image_baseUrl/speech_bubble.jpg" alt="Speech bubble" width="71" height="42" align="absmiddle" /></td>
			  </tr>
  				<tr>
    				<td width="66" align="left" valign="top">
                    <img src="$image_baseUrl/left_quote.jpg" width="56" height="50" alt="left_quote" /></td>
    				<td width="498" align="center" valign="top" bgcolor="#fcfcfc" style="font-family: Helvetica, Arial, sans-serif; color: #757887; font-size: 14px; line-height:1.4em;">Business and Bling is the only affordible way that business owners can get their business plan ready for investment.</td>
    				<td width="66" align="right" valign="bottom">
                    <img src="$image_baseUrl/right_quote.jpg" width="56" height="50" alt="right_quote" /></td>
  				</tr>
  				<tr>
  				  <td align="left" valign="top">&nbsp;</td>
  				  <td align="center" valign="top" bgcolor="#fcfcfc" style="font-family: Helvetica, Arial, sans-serif; color: #757887; font-size: 14px;">&nbsp;</td>
  				  <td align="right" valign="bottom">&nbsp;</td>
			  </tr>
			</table>
            <!-- END OF QUOTE TABLE -->
            <p><strong>PS - In case you forget, your username is $username. Keep this safe!</strong></p>
            <!-- START OF FOOTER TABLE -->
            <table width="650" border="0" cellspacing="0" cellpadding="0" bgcolor="#fcfcfc">
            
             <tr>
                <td height="26" colspan="4"  align="left" valign="top" bgcolor="#fcfcfc">&nbsp;</td>
              </tr>
              
              
              <tr>
                <td height="93" colspan="2"  align="left" valign="top" bgcolor="#ededed"><a href="#"><img src="$image_baseUrl/bottom_logo.jpg" alt="logo" width="397" height="93" border="0" /></a></td>
                <td height="93" width="281" align="right" valign="middle" bgcolor="#ededed"><a href="#"><img src="$image_baseUrl/facebook.jpg" alt="Facebook" width="30" height="22" border="0" /></a>
                  <a href="#"><img src="$image_baseUrl/twitter.jpg" alt="Twitter" width="30" height="22" border="0" /></a></td>
                <td width="10" height="93" align="right" valign="top" bgcolor="#ededed">&nbsp;</td>
              </tr>
              <tr>
                <td width="10" height="58"  align="left" valign="top" bgcolor="#ededed">&nbsp;</td>
                <td width="349"  align="left" bgcolor="#ededed" style="font-family: Helvetica, sans-serif; font-size: 11px; color: #757887; line-height: 16px;">Copyright © 2011 Business and Bling. All Rights Reserved.<br />
                UK | <a href="mailto:$mail_to" style="color:#2d78d2;">info@businessandbling.co.uk</a></td>
                <td align="right" bgcolor="#ededed"style="font-family: Helvetica, sans-serif; font-size: 11px; color: #2d78d2; line-height: 16px;">&nbsp;</td>
                <td height="58" align="right" valign="top" bgcolor="#ededed">&nbsp;</td>
              </tr>
             
            </table>
            <!-- END OF FOOTER TABLE -->
         
          </td>
        </tr>
      </table><!-- END OF EMAIL WRAPPER -->
      
	</td>
  </tr>
</table><!-- END OF PAGE WRAPPER -->

</body>
		
EOF;
        $Investor_content = <<<EOF
        
<body>
<style type="text/css">
<!--
body {
   background-color: #262626;
   margin: 0;
   padding: 0;
}
a {
	color:#2d78d2;
	text-decoration:none;
}
a:hover {
	color:#2d78d2;
	text-decoration:underline;
}
img {
	border: none;
	}
-->
</style>
<!-- START OF PAGE WRAPPER -->
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#262626">
  <tr>
    <td valign="top">

    	<!-- START OF ACCESSIBILITY MESSAGE -->
    	<table width="650" border="0" align="center" cellpadding="10" cellspacing="0" bgcolor="#262626">
  			<tr>
    				<td width="58%" style="font-family: Arial, Helvetica, sans-serif; font-size: 11px; color: #768390;"><p>Don't miss out, add <a href="#" style="color:#2d78d2; font-family: Helvetica, Arial, sans-serif;">info@businessandbling.co.uk</a> to your address book</p></td>
    				<td width="19%" style="font-family: Arial, Helvetica, sans-serif; font-size: 11px; color: #768390;"><p><a href="#" style="color:#2d78d2; font-family: Helvetica, Arial, sans-serif;">Forward to a friend</a></p></td>
    				<td width="23%" style="font-family: Arial, Helvetica, sans-serif; font-size: 11px; color: #768390;"><p>View Online <a href="$base_url" style="color:#2d78d2; font-family: Helvetica, Arial, sans-serif;">Click Here</a></p></td>
  			</tr>
		</table>
		<!-- END OF ACCESSIBILITY MESSAGE -->
      
      
      <!-- START OF EMAIL WRAPPER -->
      <table width="650" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#fcfcfc">
        <tr>
          <td>
            
            <!-- START OF Header Table -->
            <table width="650" height="93" border="0" cellspacing="0" cellpadding="0" bgcolor="#fcfcfc">
              <tr>
                <td height="93" width="415"  align="left" valign="top" bgcolor="#ededed"><img src="$image_baseUrl/logo.jpg" width="397" height="93" alt="your logo text here" /></td>
                <td width="189" align="right" valign="middle" bgcolor="#ededed"><a href="#"><img src="$image_baseUrl/facebook.jpg" alt="Facebook" width="30" height="22" border="0" /></a>
                <a href="https://twitter.com/#!/businessbling"><img src="$image_baseUrl/twitter.jpg" alt="Twitter" width="30" height="22" border="0" /></a></td>
                <td width="10" height="93" align="right" valign="top" bgcolor="#ededed">&nbsp;</td>
              </tr>
            </table>
            <!-- END OF Header Table -->
            
           
            
 
            
            <!-- START OF full width Table --> 
            <table width="630" border="0" align="center" cellpadding="0" cellspacing="0">
              <tr>
                <td height="50" colspan="2" align="left" valign="middle" bgcolor="#fcfcfc" style="font-family: Helvetica, Arial, sans-serif; color: #313035; font-size: 22px; letter-spacing: -1px;">Investigate, then Invest.</td>
              </tr>
              <tr>
                <td width="630" align="left" valign="top" style="font-family: Helvetica, Arial, sans-serif; font-size: 12px; color: #757887; line-height: 18px;"><p>Welcome to Business and Bling. We try and do things a bit differently for entrepreneurs and investors. Our main aim is to ensure that good business ideas receive the funding they need. </p>
                  <p>We take this responsibility strongly and have thus created a range of features that will help you, the investor to fully investigate an idea and its director before you contact them. </p>
                  <p>The stand-out feature that we have is the ability to see full business plans and management CVs before contacting a business owner. Other features include the business shortlist feature which means you can save several business ideas for later viewing. </p>
                  <p>We hope you find us useful. If not, we encourageyou to send us feedback to feedback@businessandbling.co.uk </p>
                  <p><strong>PS - In case you forget, your username is $username. Keep this safe!</strong></p>
                <p>&nbsp;</p></td>
              </tr>
              <tr>
                <td style="font-family: Helvetica, sans-serif; font-size: 13px; color: #373737; line-height: 16px;">&nbsp;</td>
              </tr>
            </table>
            <!-- END OF full width Table -->

         
            
            <!-- START OF FOOTER TABLE -->
            <table width="650" border="0" cellspacing="0" cellpadding="0" bgcolor="#fcfcfc">
            
             <tr>
                <td height="26" colspan="4"  align="left" valign="top" bgcolor="#fcfcfc">&nbsp;</td>
              </tr>
              
              
              <tr>
                <td height="93" colspan="2"  align="left" valign="top" bgcolor="#ededed"><a href="#"><img src="$image_baseUrl/bottom_logo.jpg" alt="logo" width="397" height="93" border="0" /></a></td>
                <td height="93" width="281" align="right" valign="middle" bgcolor="#ededed"><a href="#"><img src="$image_baseUrl/facebook.jpg" alt="Facebook" width="30" height="22" border="0" /></a>
                  <a href="#"><img src="$image_baseUrl/twitter.jpg" alt="Twitter" width="30" height="22" border="0" /></a></td>
                <td width="10" height="93" align="right" valign="top" bgcolor="#ededed">&nbsp;</td>
              </tr>
              <tr>
                <td width="10" height="58"  align="left" valign="top" bgcolor="#ededed">&nbsp;</td>
                <td width="349"  align="left" bgcolor="#ededed" style="font-family: Helvetica, sans-serif; font-size: 11px; color: #757887; line-height: 16px;">Copyright © 2011 Business and Bling. All Rights Reserved.<br />
                Hertfordshire | <a href="mailto:$mail_to" style="color:#2d78d2;">info@businessandbling.co.uk</a></td>
                <td align="right" bgcolor="#ededed"style="font-family: Helvetica, sans-serif; font-size: 11px; color: #2d78d2; line-height: 16px;">&nbsp;</td>
                <td height="58" align="right" valign="top" bgcolor="#ededed">&nbsp;</td>
              </tr>
             
            </table>
            <!-- END OF FOOTER TABLE -->
            
            
            
            
          </td>
        </tr>
      </table><!-- END OF EMAIL WRAPPER -->
      
	</td>
  </tr>
</table><!-- END OF PAGE WRAPPER -->

</body>
        
EOF;
		
		switch ($user->select_role){
			case 'Entrepenuer':
			     $content = $Entrepenuer_content;
			     break;
			case 'Investor':
			    $content = $Investor_content;
			    break;
			default:
				return ;
		}
		
		$subject = 'Confirmation of registration succeed';
		$sendTo = $user->email;
		$toName = $user->username;
		
		return $this->sendGoogleMail ( $subject, $content, $sendTo, $toName );
	}
	
	public function sendConfirmEmail($user) {
		
		$url = $this->getFullBasePath () . '/user/index/confirm/key/' . $user->confirm_key;
		$base_url = $this->getFullBasePath ();
		$subject = 'Confirmation of registration';
		//$content = '<p>Thanks for registering with us, please click the link below to confirm your account.</p>
//<p><a href="' . $url . '" >Click to complete your registration</a></p>';

		$image_baseUrl = $this->getFullBasePath () . '/media/images' ;
		
		$configEntity = new Default_Model_Entity_Config ();
		$mail_to = $configEntity->getCodeValue ( 'send_admin' );
		
        $content = <<<EOF
<body>
<style type="text/css">
<!--
body {
   background-color: #262626;
   margin: 0;
   padding: 0;
}
a {
	color:#2d78d2;
	text-decoration:none;
}
a:hover {
	color:#2d78d2;
	text-decoration:underline;
}
img {
	border: none;
	}
-->
</style>
        <!-- START OF PAGE WRAPPER -->
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#262626">
  <tr>
    <td valign="top">
    	<!-- START OF ACCESSIBILITY MESSAGE -->
    	<table width="650" border="0" align="center" cellpadding="10" cellspacing="0" bgcolor="#262626">
  			<tr>
    				<td width="58%" style="font-family: Arial, Helvetica, sans-serif; font-size: 11px; color: #768390;"><p>Don't miss out, add <a href="#" style="color:#2d78d2; font-family: Helvetica, Arial, sans-serif;">info@businessandbling.co.uk</a> to your address book</p></td>
    				<td width="19%" style="font-family: Arial, Helvetica, sans-serif; font-size: 11px; color: #768390;"><p><a href="#" style="color:#2d78d2; font-family: Helvetica, Arial, sans-serif;">Forward to a friend</a></p></td>
    				<td width="23%" style="font-family: Arial, Helvetica, sans-serif; font-size: 11px; color: #768390;"><p>View Online <a href="$base_url" style="color:#2d78d2; font-family: Helvetica, Arial, sans-serif;">Click Here</a></p></td>
  			</tr>
		</table>
		<!-- END OF ACCESSIBILITY MESSAGE -->    
      <!-- START OF EMAIL WRAPPER -->
      <table width="650" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#fcfcfc">
        <tr>
          <td>
            
            <!-- START OF Header Table -->
            <table width="650" height="93" border="0" cellspacing="0" cellpadding="0" bgcolor="#fcfcfc">
              <tr>
                <td height="93" width="415"  align="left" valign="top" bgcolor="#ededed"><img src="$image_baseUrl/logo.jpg" width="397" height="93" alt="your logo text here" /></td>
                <td width="189" align="right" valign="middle" bgcolor="#ededed"><a href="#"><img src="$image_baseUrl/facebook.jpg" alt="Facebook" width="30" height="22" border="0" /></a>
                <a href="https://twitter.com/#!/businessbling"><img src="$image_baseUrl/twitter.jpg" alt="Twitter" width="30" height="22" border="0" /></a></td>
                <td width="10" height="93" align="right" valign="top" bgcolor="#ededed">&nbsp;</td>
              </tr>
            </table>
            <!-- END OF Header Table -->        
            <!-- START OF full width Table --> 
            <table width="630" border="0" align="center" cellpadding="0" cellspacing="0">
              <tr>
                <td height="50" colspan="2" align="left" valign="middle" bgcolor="#fcfcfc" style="font-family: Helvetica, Arial, sans-serif; color: #313035; font-size: 22px; letter-spacing: -1px;">You're one step away. </td>
              </tr>
              <tr>
                <td width="630" align="left" valign="top" style="font-family: Helvetica, Arial, sans-serif; font-size: 12px; color: #757887; line-height: 18px;"><p>Thanks for registering with us, please click the link below to confirm your account. </p>
                  <p><a href="$url" target="_blank">Click to complete your registration</a></p>
                <p>&nbsp;</p></td>
              </tr>
              <tr>
                <td style="font-family: Helvetica, sans-serif; font-size: 13px; color: #373737; line-height: 16px;">&nbsp;</td>
              </tr>
            </table>
            <!-- END OF full width Table -->    
            <!-- START OF FOOTER TABLE -->
            <table width="650" border="0" cellspacing="0" cellpadding="0" bgcolor="#fcfcfc">
            
             <tr>
                <td height="26" colspan="4"  align="left" valign="top" bgcolor="#fcfcfc">&nbsp;</td>
              </tr>       
              <tr>
                <td height="93" colspan="2"  align="left" valign="top" bgcolor="#ededed"><a href="#"><img src="$image_baseUrl/bottom_logo.jpg" alt="logo" width="397" height="93" border="0" /></a></td>
                <td height="93" width="281" align="right" valign="middle" bgcolor="#ededed"><a href="#"><img src="$image_baseUrl/facebook.jpg" alt="Facebook" width="30" height="22" border="0" /></a>
                  <a href="#"><img src="$image_baseUrl/twitter.jpg" alt="Twitter" width="30" height="22" border="0" /></a></td>
                <td width="10" height="93" align="right" valign="top" bgcolor="#ededed">&nbsp;</td>
              </tr>
              <tr>
                <td width="10" height="58"  align="left" valign="top" bgcolor="#ededed">&nbsp;</td>
                <td width="349"  align="left" bgcolor="#ededed" style="font-family: Helvetica, sans-serif; font-size: 11px; color: #757887; line-height: 16px;">Copyright © 2011 Business and Bling. All Rights Reserved.<br />
                Hertfordshire | <a href="mailto:$mail_to" style="color:#2d78d2;">info@businessandbling.co.uk</a></td>
                <td align="right" bgcolor="#ededed"style="font-family: Helvetica, sans-serif; font-size: 11px; color: #2d78d2; line-height: 16px;">&nbsp;</td>
                <td height="58" align="right" valign="top" bgcolor="#ededed">&nbsp;</td>
              </tr>          
            </table>
            <!-- END OF FOOTER TABLE -->           
          </td>
        </tr>
      </table><!-- END OF EMAIL WRAPPER -->      
	</td>
  </tr>
</table><!-- END OF PAGE WRAPPER -->
</body>
EOF;
		
		
		$sendTo = $user->email;
		$toName = $user->username;
		
		return $this->sendGoogleMail ( $subject, $content, $sendTo, $toName );
	}
	
    public function sendForgotPasswordEmail($user) {
		
		$url = $this->getFullBasePath () . '/user/index/reset-password/key/' . $user->confirm_key;
		$subject = 'Reset Password';
		$content = '<p>Click on the link below to reset the new password. If you can not click it , copy this url</p>
<p><a href="' . $url . '" >' . $url .'</a></p>';
		$sendTo = $user->email;
		$toName = $user->username;
		
		return $this->sendGoogleMail ( $subject, $content, $sendTo, $toName );
	}
	
	public function sendResetPasswordEmail($user){
		//$url = $this->getFullBasePath () . '/user/index/reset-password/key/' . $user->confirm_key;
		$subject = 'Reset Password Success';
		$content = '<p>'. $user->username . ', Your password was retrieve success! New password is '.$user->password.'</p>';		
		$sendTo = $user->email;
		$toName = $user->username;
		
		return $this->sendGoogleMail ( $subject, $content, $sendTo, $toName );
	}
	
	public function sendGoogleMail($subject, $content, $sendTo, $toName = ''){
		$headers  = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
        $headers .= 'From: ' . $this->username . "\r\n";
		$result = mail($sendTo,$subject, $content, $headers);
		return $result;
	}
	
	/*public function sendGoogleMail($subject, $content, $sendTo, $toName = 'Dear Customer', $ssl = 'ssl') {
		$flag = array ();
		$googleSmtp = 'smtp.gmail.com';
		$config = array ('auth' => 'login', 'username' => $this->username, 'password' => $this->password, 'ssl' => $ssl, 'port' => 465 );
		$mailTransport = new Zend_Mail_Transport_Smtp ( $googleSmtp, $config );
		
		$this->setBodyHtml ( $content );
		$this->setSubject ( $subject );
		$this->setFrom ( $this->username );
		//$sendTo = 'chen.qiao@evebit.com';
		$sendToArr = explode ( ';', $sendTo );
		if ($toName) {
			$toNameArr = explode ( ';', $toName );
		}
		foreach ( $sendToArr as $key => $send ) {
			if ($toNameArr && @$toNameArr [$key]) {
				$this->addTo ( $send, $toNameArr [$key] );
			} else {
				$this->addTo ( $send );
			}
			
			try {
				$rs = $this->send ( $mailTransport );
			} catch ( Exception $e ) {
				$rs = false;
			}
		}
		return $rs;
	}*/
}